package com.chuyi.uilibrary.ui.refresh;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Created by sjx on 2022/7/22
 * 通用下拉刷新View
 */
public abstract class HiOverView extends FrameLayout {

    public enum HiRefreshState {

        /* 初始态 */
        STATE_INIT,

        /* Header展示的状态 */
        STATE_VISIBLE,

        /* 超出可刷新距离的状态 */
        STATE_OVER,

        /* 刷新中的状态 */
        STATE_REFRESH,

        /* 超出刷新位置松开手后的状态 */
        STATE_OVER_RELEASE,

    }

    private HiRefreshState hiRefreshState = HiRefreshState.STATE_INIT;

    /* 触发下拉刷新，需要的最小高度 */
    public int pullRefreshHeight;

    /* 最小阻尼 */
    public float minDamp = 1.6f;

    /* 最大阻尼 */
    public float maxDamp = 2.2f;

    protected void preInit() {
        pullRefreshHeight = 132;
        init();
    }

    protected abstract void init();

    protected abstract void onScroll(int scrollY, int pullRefreshHeight);

    /**
     * 显示overlay
     *
     * @return
     */
    protected abstract void onVisible();

    /**
     * 超过overlay，释放就会加载
     *
     * @return
     */
    protected abstract void onOver();

    /**
     * 开始加载
     *
     * @return
     */
    protected abstract void onRefresh();

    /**
     * 加载完成
     *
     * @return
     */
    protected abstract void onFinish();

    public HiRefreshState getHiRefreshState() {
        return hiRefreshState;
    }

    public void setHiRefreshState(HiRefreshState hiRefreshState) {
        this.hiRefreshState = hiRefreshState;
    }

    public HiOverView(@NonNull Context context) {
        this(context, null);
    }

    public HiOverView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public HiOverView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

}
